package smashedapples.core
{
	import flash.events.Event;
	
	import mx.containers.Canvas;
	
	import smashedapples.events.ModelEvent;
    
    use namespace smashedns;
    
    
    [Style(name="controller", type="Class", inherit="no")]
   
    
	public class View extends Canvas
	{	
		 /**
		 *    internal namespace controller
		 */		
		smashedns var $controller : Controller;

		
		/**
		 * 
		 *  Constructor 
		 * 
		 */		
		public function View()
		{
			super();
			this.percentHeight = 100;
			this.percentWidth = 100;
		}
		
		override protected function commitProperties():void
		{
			super.commitProperties();
			
			var ControllerClass : Class = this.getStyle("controller");
			if( ControllerClass != null)
			{
				smashedns::$controller = new ControllerClass();	
				smashedns::$controller.$view = this;
			}
		}
		
		
		/**
		 *  
		 *  We override the dispatchEvent function so that we can catch all events coming from
		 *  our component
		 * 
		 * @param event 
		 * @return Boolean
		 * 
		 */		
		
		override public function dispatchEvent(event:Event):Boolean
		{	
			if(smashedns::$controller != null)
				smashedns::$controller.execute( event );
				
			return super.dispatchEvent(event);
		}
		
		
	}
}